package com.srv.service;

import java.util.ArrayList;
import java.util.HashMap;

import com.srv.util.ObjectField;
import com.srv.TheException;
import com.srv.model.ID;
import com.srv.model.SummaryUser;
import com.srv.model.Travel;
import com.srv.persistence.PersistenceFactory;
public class TravelService extends Service{
	/**
	 * 删除
	 * @param theTravelID
	 * @throws TheException
	 */
	public static void del(String theTravelID) throws TheException{
		ID idObj = IDService.getID(theTravelID);
		if(idObj==null){return;}
		PersistenceFactory.getNodePersistence().deleteNode(idObj.pid, theTravelID);
	}
	/**
	 * 保存对象
	 * @param theTravel
	 * @throws TheException
	 */
	public static void save(Travel theTravel) throws TheException {
		PersistenceFactory.getTravelPersistence().insertTravel(theTravel);
	}
	/**
	 * 返回Travel
	 * @param pid
	 * @param travelID
	 * @return
	 * @throws PersistenceException
	 */
	public static Travel getTravel(long pid,String travelID) throws TheException{				
		return PersistenceFactory.getTravelPersistence().getTravel(pid, travelID);
		
	}
	/**
	 * 返回某个用户的Travel列表
	 * @param theOwner - 资源所属用户
	 * @return
	 * @throws PersistenceException
	 */
	public static ArrayList<Travel> list(SummaryUser theOwner) throws TheException{		
		HashMap<ObjectField,Object> keyValues = new HashMap<ObjectField, Object>();	
		return (ArrayList<Travel>)PersistenceFactory.getTravelPersistence().queryTravelList(theOwner.pid, keyValues);
		
	}
}
